package com.moive.news.tqnewsapplication.base.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/26.
 */
public abstract class BaseListAdapter<D> extends BaseAdapter {
    protected ArrayList<D> arrayLists=new ArrayList<>();
    private int currentPage = 1;
    private int pageCount = 10;
    public void addItems(List<D> arrayList){
        arrayLists.clear();
        this.arrayLists.addAll(arrayList);
        notifyDataSetChanged();
    }
    public void addMoreItems(List<D> arrayList){

        this.arrayLists.addAll(arrayList);
        notifyDataSetChanged();
    }
    public void addSingleItems(D arrayList){
        this.arrayLists.add(arrayList);
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return arrayLists.size();
    }

    @Override
    public D getItem(int position) {
        return arrayLists.get(position);
    }
    public void removeItem(D position){
        arrayLists.remove(position);
        notifyDataSetChanged();
    }
    public void selectRemoveItem(List<D> arrayList){
        arrayLists.clear();
        this.arrayLists.addAll(arrayList);
        notifyDataSetChanged();
    }
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getItemView(position, convertView, parent, arrayLists);
    }
    public int getCurPage() {
        return currentPage;
    }


    public int getPageCount() {
        return pageCount;
    }

    public void clearData() {
        arrayLists.clear();
        currentPage = 1;
    }

    protected abstract View getItemView(int position, View convertView, ViewGroup parent, List<D> item);
}
